#ifndef WebMonitor_H
#define WebMonitor_H

#include "WSMonitor.h"
#include <string>
#include <fstream>
#include <mutex>
#include <thread>
#include <atomic>
#include <condition_variable>
#include <oatpp/network/tcp/client/ConnectionProvider.hpp>
#include <oatpp-websocket/WebSocket.hpp>
#include <oatpp-websocket/Connector.hpp>
#include <fmt/format.h>
#include "RemoteHandle.h"
#include "Client.h"

class WebMonitor
{
public:
    WebMonitor(Client* evtHandler,RemoteHandle* remoteHandle);
    virtual ~WebMonitor();
    void LoginServer();
    bool GetConnectStatus();
    bool SetServerConfig(std::string IPaddr,std::string Port,std::string DeviceName);
    bool GetLoginStatus();
private:
    RemoteHandle* _remoteHandle;
    void UploadTask();
    void ListenTask();
    bool loginSuccess=false;
    std::mutex socketWriteMutex;
    Client* _evtHandler;
    std::thread uploadThread;
    //基本信息
    std::string IPAddress;
    std::string Port;
    std::string DeviceName;
    std::shared_ptr<oatpp::websocket::WebSocket> socket;

    std::mutex dataMut;
    oatpp::String imgData;
    std::condition_variable uploadCond;
    std::atomic<bool> dataReady=false;
    std::atomic<bool> uploadExitFlag=false;
    std::atomic<bool> connectFlag=false;
};

#endif